﻿package mortal.game.view.guildWar
{
    import Message.Public.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class GuildWarIcon extends ActionBaseIcon
    {
        private static var _instance:GuildWarIcon;

        public function GuildWarIcon()
        {
            super(ResFileConst.GuildWarIcon);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.updateTimeTip();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            this.stopEffect();
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarEnterWindowShow, true));
            return;
        }// end function

        protected function updateTimeTip() : void
        {
            var _loc_2:Date = null;
            var _loc_3:Date = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_1:* = Cache.instance.guildWar.guildWarOpen;
            if (_loc_1)
            {
                _loc_2 = _loc_1.openDt;
                _loc_3 = _loc_1.endDt;
                _loc_4 = (_loc_2.time - ClockManager.instance.nowDate.time) / 1000;
                if (_loc_4 > 0)
                {
                    this.setLeftTimeAndState(_loc_4, 1);
                }
                else
                {
                    _loc_5 = (_loc_3.time - ClockManager.instance.nowDate.time) / 1000;
                    if (_loc_5 > 0)
                    {
                        this.playEffect();
                        this.setLeftTimeAndState(_loc_5, 2);
                    }
                }
            }
            return;
        }// end function

        override protected function timeOutCaller() : void
        {
            if (_state == 1)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWarEnterWindowShow, false));
                playEffect();
            }
            this.updateTimeTip();
            return;
        }// end function

        public static function get instance() : GuildWarIcon
        {
            if (!_instance)
            {
                _instance = new GuildWarIcon;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
